#include <iostream>
#include <string.h>

using namespace std;

int coin[52];
int ntable, ncoin;
int table[12];
int tt[6];

int ans[12][2]; // 0 for min ,1 for max


int gcd(int a, int b)
{
    int temp;
    if (a<b) 
    {
        temp = a;
        a = b;
        b = temp;
    }    
    while (a%b)
    {
        temp = a %b;
        a = b;
        b = temp;
    }   
    return b; 
}
    

int gnd(int a1, int a2, int a3, int a4)
{
    int max;
    
    max = a1*a2/gcd(a1,a2);
    max = max*a3/gcd(max,a3);
    max = max*a4/gcd(max,a4);

   	return max;
}    

void count()
{
    int bei, time, sum, k;
    bei = gnd( coin[tt[1]], coin[tt[2]], coin[tt[3]] , coin[tt[4]]);
   for (k=1; k<=ntable; ++k)
    {
       if (ans[k][0] == ans[k][1]) continue;
        time = table[k] / bei;
        sum = time*bei;
        if (sum > ans[k][0]) ans[k][0] = sum;
        if (sum < table[k]) sum +=bei;
        if (sum < ans[k][1]) ans[k][1] = sum;
    }    
}    


int main()
{
    int i,j,k,temp1, temp2;
    while (scanf("%d%d", &ncoin , &ntable)==2)
    {
        if (!ncoin && !ntable) break;
        for (i=1; i<=ncoin; ++i)
        	scanf("%d", &coin[i]);
       	for (j=1; j<=ntable; ++j)
       		scanf("%d", &table[j]);
       		
    	for (i=1; i<=ntable; ++i)
  		{
  			ans[i][0] = 0;
  			ans[i][1] = 2000000000;
        } 			

  		for (tt[1]=1; tt[1]<=ncoin-3; ++tt[1])
  			for (tt[2]=tt[1]+1; tt[2]<=ncoin-2; ++tt[2])
  				for (tt[3]=tt[2]+1; tt[3]<=ncoin-1; ++tt[3])
  					for (tt[4]=tt[3]+1; tt[4]<=ncoin; ++tt[4])
  						count();
 
  						
  		for (i=1; i<=ntable; ++i)
  			printf("%d %d\n", ans[i][0],ans[i][1]);
      		
        	
        
    }
    
    
    return 0;
}    
/*
4 1
50
100
200
400
2000
0 2000000000
*/


